package com.king.student.sql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqlUtility {

	/*
	 * 由于是单线程的程序，所以不考虑高并发等情况，
	 * 全程只用一个数据库链接即可
	 * 这里连接的生命周期是从程序运行开始到结束
	 */
	
	private static Connection connection;
	private static final String DB_URL = "jdbc:mysql:///studentManager?useUnicode=true&characterEncoding=utf8&useSSL=false";
	private static final String USER = "root";
	private static final String PASSWORD = "123456";
	
	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			connection = DriverManager.getConnection(DB_URL, USER, PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() {
		return connection;
	}
	
}
